import 'package:flutter/material.dart';
import 'package:untitled/utils/SnackBarHepler.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      scaffoldMessengerKey: ScaffoldMessengerGlobalKey,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with SingleTickerProviderStateMixin {
  bool isCheck = false;
  List<String> selectList = [];
  @override
  Widget build(BuildContext context) {
    //脚手架
    return Scaffold(
      appBar: AppBar(
        title: Text('复选框'),
        backgroundColor: Colors.blue,
        foregroundColor: Colors.white,
      ),

      body: SizedBox.expand(
        child: Column(
          children: [
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Checkbox(
                  value: isCheck,
                  onChanged: (bool? value) {
                    setState(() {
                      isCheck = value ?? false;
                    });
                  },
                ),
                Text('数学 '),
              ],
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Checkbox(
                  value: selectList.contains('语文'),
                  onChanged: (bool? value) {
                    setState(() {
                      if (value!) {
                        selectList.add('语文');
                      } else {
                        selectList.remove('语文');
                      }
                    });
                  },
                ),
                Text('语文 '),
              ],
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Checkbox(
                  value: selectList.contains('英文'),
                  activeColor: Colors.red,
                  checkColor: Colors.white,
                  side: BorderSide(width: 4, color: Colors.grey),

                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(40),
                  ),
                  onChanged: (bool? value) {
                    setState(() {
                      if (value!) {
                        selectList.add('英文');
                      } else {
                        selectList.remove('英文');
                      }
                    });
                  },
                ),
                Text('英文 '),
              ],
            ),

            CheckboxListTile(
              value: isCheck,
              title: Text("数学常数"),
              subtitle: Text("这里是第二行"),
              titleAlignment: ListTileTitleAlignment.bottom,
              onChanged: (bool? value) {
                setState(() {
                  isCheck = value ?? false;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
